package cn.itsource.pet.controller;

import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.SearchMasterMsg;
import cn.itsource.pet.query.PetQuery;
import cn.itsource.pet.query.SearchMasterMsgQuery;
import cn.itsource.pet.service.IPetService;
import cn.itsource.pet.service.ISearchMasterMsgService;
import cn.itsource.pet.domain.Pet;
import cn.itsource.product.domain.Product;
import cn.itsource.product.query.ProductQuery;
import cn.itsource.user.domain.LoginInfo;
import cn.itsource.user.domain.User;
import cn.itsource.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/pet")
public class PetCotroller {
    @Autowired
    private IPetService petService;

    //分页查询
    @PostMapping
    public PageList<Pet> queryPage(@RequestBody PetQuery query){
        //获取当前的系统登录用户--loginInfo--employee
        //查询t_shop 表根据 employee id  ---Shop
        query.setShopId(27L);//本来时动态
        return petService.queryPage(query);
    }

    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Pet pet){
        try {
            if (pet.getId() != null) {
                petService.update(pet);
            }else{
                petService.add(pet);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me()
                    .setMessage("操作失败！"+e.getMessage());
        }
    }

    //分页 前端普通用户
    @PostMapping("/list")
    public PageList<Pet> queryPageList(@RequestBody PetQuery query){
        query.setState(1);
        return petService.queryPage(query);
    }

}
